<!-- 模板区域设计操作工具类 -->
<style>
.codeModule{ display:block; z-index:900;border:2px dashed #999;} 
</style>
<script>
var thisCtrObj = null;
$(function(){
	
	$("[data-temp-code]").each(function(){
		var thisId = $(this).attr("id");
		if($("[id='"+thisId+"']").length>1){
			layer.alert("有元素id="+thisId+" 重复啦，请检查！");
		}
		if($(this).html()!=null && $(this).html()==""){
			$(this).html("<div class='temp-box2'>此区域用于填充栏目"+$(this).attr("data-temp-code")+"数据</div>");
		};
		$(this).mouseover(function(){	//1、绑定鼠标移入事件
			var defHeight = "240";
			if($(this).height()>defHeight) {
				defHeight = $(this).height();
			}
			$(this).css("height",defHeight);
			$(this).attr("title","双击可以进行设置");
			$(this).addClass("fcur").addClass("codeModule");
		}).mouseout(function(){	//2、绑定鼠标移出事件
			$(this).removeAttr("title").removeAttr("style");
			$(this).removeClass("fcur").removeClass("codeModule");
		}).dblclick(function(){	//3、绑定鼠标双击事件
			var obj = $(this);
			thisCtrObj = obj;
			
			layer.open({
			  title:"模板区域设置",
			  type: 1,
			  skin: "layui-layer-rim", //加上边框
			  shadeClose: true, //开启遮罩关闭
			  area: ['520px', '380px'], //宽高
			  content: $("#box-temp-attr-set")
			});
			
			//修改时返显
			if(channelMap[obj.attr("data-temp-code")]){
				$("#select_tempCode").val(obj.attr("data-temp-code"));
			}else{
				$("#select_tempCode").val("");
			}
			$("#input_tempId").val(obj.attr("id"));
			$("#input_tempType").val(obj.attr("data-temp-type"));
			$("#input_tempRows").val(obj.attr("data-temp-rows"));
		});	
	});
	
	initChannelSelect();
});

//保存修改值
function saveBtnTempInc(tempCodeId,tempTypeId,tempRowsId){
	var tempCodeVal = $(tempCodeId).val();
	var tempTypeVal = $(tempTypeId).val();
	var tempRowsVal = $(tempRowsId).val();
	if(strUtil.isNull(tempCodeVal)){
		layer.tips("不能为空！", tempCodeId,{tips: 3});
		return;
	}
	if(strUtil.isNull(tempTypeVal)){
		layer.tips("不能为空！", tempTypeId,{tips: 3});
		return;
	}
	
	//alert(thisCtrObj.prop("outerHTML"));
	thisCtrObj.attr("data-temp-code",tempCodeVal);
	thisCtrObj.attr("data-temp-type",tempTypeVal);
	thisCtrObj.attr("data-temp-rows",tempRowsVal);
	
	thisCtrObj.removeClass("temp-box");
	thisCtrObj.html("");
	
	var newContentText = "\t\t\t\t"+thisCtrObj.prop("outerHTML");
	var tempPath = "/"+siteCode+"/template/index.inc";
	var dataParam= {"filePath":tempPath,"code":thisCtrObj.attr("id"),"newContent":newContentText};
	var index_submit = layer.confirm("您确定要保存设置吗？", {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
	, function(){
		layer.close(index_submit);
		var msgIndex = layer.msg("正在保存文件内容...");
		$.ajax({type: "post",
			url: ctx+"/trans/template/setTemplateParams",data:dataParam, dataType:'json',
			success: function(myData){
				if("true"!=myData.flag){
					layer.alert(myData.msg);
				}else{
					parent.layer.closeAll();
				}
			}
	   });
	});
}
var channelMap = {};
//初始化ChannelSelect
function initChannelSelect(){
	var dataParam={"pageName":"channel-list","formName":"searchForm","tChannel.w_siteCode":siteCode};
	//alert(siteCode);
	 $.getJSON(common_list_url,dataParam,function(myData){
		var obj=myData.rows;
    	$("#select_tempCode").html("");
    	var optionHtml = "<option value=''>---请选择---</option>";
		for(var i = 0; i < obj.length; i++){
			channelMap[obj[i].codeName]=obj[i].codeName;
			optionHtml+="<option value='"+obj[i].codeName+"'>"+obj[i].codeName+"-"+obj[i].channelName+"</option>";
		}
		$("#select_tempCode").html(optionHtml);
	 });
}

</script>

<div id="box-temp-attr-set" style="display:none;">
	<div class="form-group">
	
		<div class="form-group col-sm-12">
			<div class="form-group col-sm-3 text-right">操作区域ID</div>
			<div class="form-group col-sm-9">
				<input id="input_tempId" class="form-control clean" maxlength="20" readonly="readonly"/>
			</div>
		</div>
		<div class="form-group col-sm-12">
			<div class="form-group col-sm-3 text-right">栏目标识</div>
			<div class="form-group col-sm-9">
				<select id="select_tempCode" class="form-control"></select>
			</div>
		</div>
		<div class="form-group col-sm-12">
			<div class="form-group col-sm-3 text-right">模板类型</div>
			<div class="form-group col-sm-9">
				<select id="input_tempType" class="form-control clean">
					<option value="">--请选择--</option>
					<option value="banner">banner-首页banner滚屏模板</option>
					<option value="bannerTitle">bannerTitle-首页banner+title滚屏模板</option>
					<option value="fontList">fontList-纯文字+日期列表</option>
					<option value="fontListDateLine">fontListDateLine-纯文字+日期+下划线列表</option>
					<option value="fontListLine">fontListLine-纯文字+下划线列表</option>
					<option value="fontImgList">fontImgList-文字+主图列表</option>
					<option value="fontImg">fontImg-最新1条文字+主图</option>
					<option value="img">img-纯主图片</option>
					<option value="fontListNewImg">fontListNewImg-最新1文章主图+文章标题列表</option>
					<option value="links">links-友情链接</option>
					<option value="thisId">【thisId-专用对接动态数据】</option>
				</select>
			</div>
		</div>
		<div class="form-group col-sm-12">
			<div class="form-group col-sm-3 text-right">记录条数</div>
			<div class="form-group col-sm-9">
				<input id="input_tempRows" class="form-control clean" maxlength="10"/>
			</div>
		</div>
		<div class="form-group col-sm-12 text-center">
			<button type="button" onclick="saveBtnTempInc('#select_tempCode','#input_tempType','#input_tempRows')" class="btn btn-danger"><i class="fa fa-cog"></i> 保存设置</button>
		</div>
	</div>
</div>